package prototech.ahedra.form;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;

public class LoginForm extends ActionForm {
	private String usr;
	private String pass;

	public String getUsr() {
		return usr;
	}

	public void setUsr(String usr) {
		this.usr = usr;
	}

	public String getPass() {
		return pass;
	}

	public void setPass(String pass) {
		this.pass = pass;
	}

	@Override
	public void reset(ActionMapping mapping, HttpServletRequest request) {
		this.usr = null;
		this.pass = null;
	}

	@Override
	public ActionErrors validate(ActionMapping mapping,
			HttpServletRequest request) {
		ActionErrors errors = new ActionErrors();
		if (usr == null || usr.trim().equals(""))
			errors.add("userRequired", new ActionMessage("login.usuario.required"));
		if (pass == null || pass.trim().equals(""))
			errors.add("passwordRequired", new ActionMessage("login.password.required"));
		return errors;
	}

}
